﻿using System;
using System.Text;
using System.Collections;
using System.Drawing;
using SdlDotNet.Core;
using SdlDotNet.Input;
using SdlDotNet.Graphics;
using SdlDotNet.Graphics.Sprites;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using SdlDotNet.Input;

namespace TiroParabola
{
    class Juego
    {
        private SpriteCollection sprites;
        private Surface pantalla;
        private Surface fondo;
        private int ancho = 800, alto = 600;

        public Juego() {
            // Inicializamos:
            sprites = new SpriteCollection();
            pantalla = Video.SetVideoMode(ancho, alto);
            fondo = new Surface("Dibujos/fondo.png");
            sprites.EnableTickEvent();
            pantalla.Blit(fondo);
            pantalla.Update();
            Events.Tick += new EventHandler<TickEventArgs>(this.Tick);
            Events.KeyboardDown += new EventHandler<KeyboardEventArgs>(this.Key);

        }
        
        public void Anyade(Objeto obj) {
            sprites.Add(obj);

        }
        public void Go() {
            Events.Run();
        }
        #region
            Collection<Rectangle> rects = new Collection<Rectangle>();
            private void Key(object sender, KeyboardEventArgs args) {
                if (args.Key.ToString() == "Space") {
                    Console.WriteLine("Espacio pulsado");
                    ((Objeto)sprites[0]).Vy = -50;
                    ((Objeto)sprites[0]).Vx = 10;
                    ((Objeto)sprites[0]).Gravedad = 3;
                }
            }
            private void Tick(object sender, TickEventArgs args)
            {
                // Dibujamos los objetos...
                rects = pantalla.Blit(sprites);
                foreach (Objeto a in sprites) {
                    a.Update();
                }
                pantalla.Update();
                pantalla.Erase(rects,fondo);
            }
        #endregion
    }
}
